package com.itheima.config;

import com.itheima.interceptor.DemoInterceptor;
import com.itheima.interceptor.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Author: Zheng
 * Date:   2024/1/27  9:18
 * Package：com.itheima.config
 * Description：
 * Version：1.0
 */
@Slf4j
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private DemoInterceptor demoInterceptor;

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("拦截器拦截到了请求~");
        //添加拦截器
        //registry.addInterceptor(demoInterceptor)
        //        //.addPathPatterns("/*")  //拦截所有一级路径
        //        .addPathPatterns("/**")  //代表拦截任意级别路径
        //        .excludePathPatterns("/login");//设置排除路径，排除login路径

        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login");
    }
}
